package com.jshop.servlet.reception;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jshop.entity.JSHOP_BOOK;
import com.jshop.entity.JSHOP_CATEGORY;
import com.jshop.service.JSHOP_BOOK_DAO;
import com.jshop.service.JSHOP_CATE_DAO;

@WebServlet("/tobookdetail")
public class ToBookDetail extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ArrayList<JSHOP_CATEGORY> flist = JSHOP_CATE_DAO.selectByRank("f");
		ArrayList<JSHOP_CATEGORY> clist = JSHOP_CATE_DAO.selectByRank("c");
		request.setAttribute("flist", flist);
		request.setAttribute("clist", clist);
		
		int id = Integer.parseInt(request.getParameter("id"));
		JSHOP_BOOK book = null;
		if(id != 0) {
			book = JSHOP_BOOK_DAO.selectById(id);
			request.setAttribute("book",book);
		}
		

		if(book != null) {
			int cid = book.getBook_cate_child();
			ArrayList<JSHOP_BOOK> blist = JSHOP_BOOK_DAO.selectByCate(cid,"c");
			request.setAttribute("blist", blist);
			
			JSHOP_CATEGORY cate = JSHOP_CATE_DAO.selectById(cid);
			request.setAttribute("cate",cate);
		}
		
		request.getRequestDispatcher("bookdetail.jsp").forward(request, response);
	}
}
